package com.cgx.controller;

import com.cgx.entity.message.Message;
import com.cgx.service.MessageService;
import com.cgx.vo.websocket.MessageVo;
import com.cgx.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * @author chenguanxin
 * @date 2021-05-25 22:38
 */
@Controller
@CrossOrigin("*")
@RequestMapping("/message")
public class MessageController {

    @Autowired
    private MessageService messageService;

    @ResponseBody
    @RequestMapping("/sendMessageToUser")
    public Map<String, ResultVo> sendMessageToUser(@RequestBody MessageVo messageVo) {
        return messageService.sendMessageToUser(messageVo);
    }

    @ResponseBody
    @RequestMapping("/saveAll")
    public Map<String, ResultVo> saveAll(@RequestBody List<Message> messageList) {
        return messageService.saveAll(messageList);
    }

    @ResponseBody
    @RequestMapping("/saveMessage")
    public Map<String, ResultVo> saveMessage(@RequestBody List<MessageVo> messageList) {
        return messageService.saveMessage(messageList);
    }

    @ResponseBody
    @RequestMapping("/getMessageBySessionId")
    public List<Message> getMessageBySessionId(@RequestBody String sessionId) {
        return messageService.getMessageBySessionId(sessionId);
    }
}
